#ifndef WORLDMODEL_H_
#define WORLDMODEL_H_

#include "common.h"

#include "../include/World.h"
#include "../include/SpatialPartitioningType.h"
#include "../include/SpatialPartitioningConfig.h"
#include "math/math.h"
#include "RigidBody.h"
#include "SpatialPartitioning.h"
#include "hset.h"
#include <string>

namespace physicsworks {

using math::vec3;

class WorldFactory;

class WorldModel : public World {
	friend class WorldFactory;
public:
	typedef HSet<RigidBody*>::Type RigidBodyHSet;

private:
	std::string name;
	real timeStepPrecision;
	std::stack<Collision*> collisions;
	SpatialPartitioning* spatialPartitioning;
	RigidBodyHSet rigidBodies;
	vec3 gravity;
	
public:
	~WorldModel() {}

	void setName(const char* name) { this->name = name; }
	const char* getName() const { return name.c_str(); }
	void add(Body* b);
	void remove(Body* b);
	void removeAll() { rigidBodies.clear(); }
	void setGravity(real gX, real gY, real gZ) { gravity(gX, gY, gZ); }
	real* getGravity() const { return gravity.toReal(); }
	Body** getBodiesList(int* size);
	const RigidBodyHSet& getBodiesListHSet() const { return rigidBodies; }
	void execute(real timeStep) {}
	void setTimeStepPrecision(real timeStep) {}
	real getTimeStepPrecision() const { return 0; }

private:
	WorldModel(const vec3& a, const vec3& b, SpatialPartitioning* sp);
	WorldModel(const WorldModel& w);
	WorldModel& operator = (const WorldModel& w);
};

}

#endif /*WORLDMODEL_H_*/
